<?php
//Route กำหนดเส้นทางภายในเว็บ
//
//Browser request เข้ามา
//ให้ url เป็น pla2.com/ชื่อร้าน
//เรียก Web ตรงๆหรือเรียก Main ให้เรียก Main
//เรียก At ให้เรียกข่าว,แผนที่ จากจังหวัด,อำเภอ,ย่าน ฯลฯ

Class Route {
	
    var $class;
    var $method;
    var $uri;
    var $params;
    
    function __construct($tailer) {
        $parse_url = parse_url($tailer);
        $this->uri = explode("/", $parse_url['path']);
        
        $uri_slice = array_slice($this->uri, 2);
        $this->params = array();
        $this->params = array_merge($this->params, $uri_slice); 
        
        if(strcasecmp(SUB,'blog') == 0){
            $this->class = 'Blog';            
            $this->name = $this->name[0];
            
            if(empty($this->uri[1])){
                $this->method = 'index';
            }
            else{
                $this->method = $this->uri[1];
            }
            return true;
        }
        
        if($this->uri[0] == 'Apps'){
            $this->class = $this->uri[1];
            $this->method = $this->uri[2];
            
            $uri_slice = array_slice($this->uri, 3);
			$this->params = array();
			$this->params = array_merge($this->params, $uri_slice); 
            
            return true;
        }
        
        if(!$this->is_fixController($this->uri[0])){
            $this->class = 'Biz';
        }
        
        if(empty($this->uri[1])){
            $this->method = 'index';
        }
        else{
            $this->method = $this->uri[1];
        }
    }
    
    function is_fixController($str){
        $arr = array(
            'Main' => 'Main',
            'At' => 'At',
            'Biz' => 'Biz',
            'User' => 'User',
            'Admin' => 'Admin',
            'BizBG' => 'BizBG',
            'Place' => 'Place'
        );
        if(empty($this->uri[0])){
            $this->class = 'Main';
            return true;
        }
        foreach($arr as $key => $value){
            if(strcasecmp($str,$value) == 0){
                $this->class = $key;
                return true;
            }
        }
        return false;
    }
    
    function load_class(){
        require_once('Controller/At.php'); return new At;
    }
}
